#include "RaiiPointer.h"

namespace dwarf {

template<>
RaiiPointer<Dwarf_Attribute>::RaiiPointer(Dwarf_Debug _debug, Dwarf_Attribute _pointer)
		: debug_(_debug),
		  type_(DW_DLA_ATTR),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<Dwarf_Attribute>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_ATTR),
		  pointer_(NULL) {
}

template<>
RaiiPointer<Dwarf_Attribute *>::RaiiPointer(Dwarf_Debug _debug, Dwarf_Attribute *_pointer)
		: debug_(_debug),
		  type_(DW_DLA_LIST),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<Dwarf_Attribute *>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_LIST),
		  pointer_(NULL) {
}

template<>
RaiiPointer<Dwarf_Block *>::RaiiPointer(Dwarf_Debug _debug, Dwarf_Block *_pointer)
		: debug_(_debug),
		  type_(DW_DLA_BLOCK),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<Dwarf_Block *>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_BLOCK),
		  pointer_(NULL) {
}

template<>
RaiiPointer<Dwarf_Die>::RaiiPointer(Dwarf_Debug _debug, Dwarf_Die _pointer)
		: debug_(_debug),
		  type_(DW_DLA_DIE),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<Dwarf_Die>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_DIE),
		  pointer_(NULL) {
}

template<>
RaiiPointer<Dwarf_Locdesc *>::RaiiPointer(Dwarf_Debug _debug, Dwarf_Locdesc *_pointer)
		: debug_(_debug),
		  type_(DW_DLA_LOCDESC),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<Dwarf_Locdesc *>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_LOCDESC),
		  pointer_(NULL) {
}

template<>
RaiiPointer<char *>::RaiiPointer(Dwarf_Debug _debug, char *_pointer)
		: debug_(_debug),
		  type_(DW_DLA_STRING),
		  pointer_(_pointer) {
}

template<>
RaiiPointer<char *>::RaiiPointer(Dwarf_Debug _debug)
		: debug_(_debug),
		  type_(DW_DLA_STRING),
		  pointer_(NULL) {
}

template<>
RaiiPointer<Dwarf_Locdesc *>::~RaiiPointer() {
	if (pointer_ == NULL) {
		return;
	}
	dwarf_dealloc(debug_, pointer_->ld_s, DW_DLA_LOC_BLOCK);
	dwarf_dealloc(debug_, pointer_, type_);
}

}
